<template>
  <div class="cartcontrol">
    <transition name="fade">
      <div class="cart-decrease" v-show="food.count>0" @click.stop.prevent="decreaseCart">
        <span class="inner icon-remove_circle_outline"></span>
      </div>
    </transition>
    <span class="cart-num" v-show="food.count>0">{{food.count}}</span>
    <span class="cart-increase icon-add_circle" @click.stop.prevent="addCart"></span>
  </div>
</template>

<script>
import Vue from 'vue';

export default {
  props: {
    food: {
      type: Object
    }
  },
  created () {
    // console.log(this.food);
  },
  methods: {
    addCart (event) {
      if (!this.food.count) {
        Vue.set(this.food, 'count', 1);
      } else {
        this.food.count++;
      }
    },
    decreaseCart () {
      if (this.food.count) {
        this.food.count--;
      }
    }
  }
};
</script>

<style lang="stylus" scoped="scoped">
  .cartcontrol
    font-size: 0
    .cart-decrease
      display: inline-block
      padding: 6px
      color: rgb(0, 160, 220)
      transform: translate3D(0, 0, 0)
      &.fade-enter-active,&.fade-leave-active
        transition: all .4s linear
      &.fade-enter, &.fade-leave-to
        transform: translate3D(24px, 0, 0)
        .inner
          transform: rotate(180deg)
      .inner
        display: inline-block
        font-size: 24px
        line-height: 24px
        transition: all .4s linear
        transform: rotate(0)
    .cart-num
      display: inline-block
      padding: 6px 0
      width: 12px
      line-height: 24px
      font-size: 10px
      text-align: center
      vertical-align: top
      color: rgb(147, 153, 159)
    .cart-increase
      display: inline-block
      padding: 6px
      color: rgb(0, 160, 220)
      font-size: 24px
      line-height: 24px
</style>
